#ifndef	_SCP_H
#define _SCP_H 

#ifdef SYMBOL_GLOBALS
   #define SCP_EXT
#else
   #define SCP_EXT extern
#endif //* SYMBOL_GLOBALS

	 
#define	SCP2_SND_BUF_LEN_MAX		256		//* 串口2发送缓冲区最长能保存的字节数	 
#define SCP2_RCV_BUF_LEN_MAX 		128		//* 串口2接收缓冲区最长能保存的字节数
	 
#define	SCP3_SND_BUF_LEN_MAX		1500	//* 串口3发送缓冲区最长能保存的字节数
#define SCP3_RCV_BUF_LEN_MAX 		3072	//* 串口3接收缓冲区最长能保存的字节数,支持GB和远程固件升级
	 
   
//* 与控制板串行通讯用到的接收缓冲区控制块
typedef struct _STCB_SCP_ {	
	OS_EVENT *hSemSentCompleted;	//* 发送完成的信号量
  OS_EVENT *hSemRecvCompleted;	//* 接收完成的信号量
	
	struct {
		INT16U usSndBufSize;
		INT8U *pubSndBuf;
	} stCBSnd;	
		
	struct {
		INT16U usReadIdx;						//* 读指针			
		INT16U usWriteIdx;					//* 写指针
		INT16U usPrevWriteIdx;			//* 上一个写索引
		
		INT32U unTotalReadBytes;		//* 读数据总数
		INT32U unTotalWriteBytes;		//* 写数据总数
			
		INT16U usRcvBufSize;
		INT8U *pubRcvBuf;
	} stCBRcv;	
} STCB_SCP, *PSTCB_SCP;

#define PARITYTP_NO     USART_Parity_No     //* 无校验
#define PARITYTP_EVEN   USART_Parity_Even   //* 偶校验
#define PARITYTP_ODD    USART_Parity_Odd    //* 奇校验

#define FLOWCTLTP_NO        USART_HardwareFlowControl_None      //* 无流控
#define FLOWCTLTP_RTS       USART_HardwareFlowControl_RTS       //* RTS
#define FLOWCTLTP_CTS       USART_HardwareFlowControl_CTS       //* CTS
#define FLOWCTLTP_RTS_CTS   USART_HardwareFlowControl_RTS_CTS   //* RTS_CTS

#define DATABIT_8           USART_WordLength_8b     //* 8个有效数据位
#define DATABIT_9           USART_WordLength_9b     //* 9个有效数据位

#define STOPBITS_0_5        USART_StopBits_0_5      //* 0.5个停止位
#define STOPBITS_1          USART_StopBits_1        //* 1个停止位
#define STOPBITS_1_5        USART_StopBits_1_5      //* 1.5个停止位
#define STOPBITS_2          USART_StopBits_2        //* 2个停止位


SCP_EXT void SCPControlBlockInit(void);

SCP_EXT BOOL SCP2Init(INT32U unBaudrate, INT16U usDataBit, INT16U usStopBits, INT16U usParityType, INT16U usFlowCtlType);
SCP_EXT INT32U SCP2Send(INT8U *pubPacket, INT32U unPacketLen);
SCP_EXT void SCP2SendString(char *pszPacket, ...);
SCP_EXT INT32U SCP2Recv(INT8U *pubRcvBuf, INT32U unRcvBufLen, INT32S nWaitSecs);
SCP_EXT void USART2_IRQHandler(void);
SCP_EXT void DMA1_Channel7_IRQHandler(void);

SCP_EXT BOOL SCP3Init(INT32U unBaudrate, INT16U usDataBit, INT16U usStopBits, INT16U usParityType, INT16U usFlowCtlType);
SCP_EXT void SCP3ReInit(void);
SCP_EXT INT32U SCP3Send(INT8U *pubPacket, INT32U unPacketLen);
SCP_EXT INT32U SCP3Recv(INT8U *pubRcvBuf, INT32U unRcvBufLen, INT32S nWaitSecs);
SCP_EXT void USART3_IRQHandler(void);
SCP_EXT void DMA1_Channel2_IRQHandler(void);


#endif


